{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4bb71af4",
   "metadata": {},
   "source": [
    "# TimeSeries\n",
    "## datetime\n",
    "1. datetime.datetime\n",
    "2. datetime.delta\n",
    "3. datetime.strftime(format)\n",
    "4. datetime.strptime(str,format)\n",
    "\n",
    "<hr>\n",
    "\n",
    "1. pd.to_datetime()\n",
    "2. pd.isnull() 能够判断是否是NaT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d89e4234",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023 year\n",
      "3 month\n",
      "18 day\n",
      "16:\n",
      "40:\n",
      "42\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime, timedelta\n",
    "\n",
    "now = datetime.now()\n",
    "print(str(now.year) + \" year\")\n",
    "print(str(now.month) + \" month\")\n",
    "print(str(now.day) + \" day\")\n",
    "print(str(now.hour) + \":\")\n",
    "print(str(now.minute) + \":\")\n",
    "print(str(now.second))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9d85ff19",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-3 0\n"
     ]
    }
   ],
   "source": [
    "date1 = datetime(2023,11,2)\n",
    "date2 = datetime(2023,11,5)\n",
    "delta = date1 - date2\n",
    "print(delta.days, delta.seconds)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "06540c9b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2023-03-18 16:51:46'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "now = datetime.now()\n",
    "str = now.strftime(\"%Y-%m-%d %H:%M:%S\")\n",
    "str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "af665267",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2023, 3, 18, 16, 51, 46)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time = datetime.strptime(str,\"%Y-%m-%d %H:%M:%S\")\n",
    "time"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c059627",
   "metadata": {},
   "source": [
    "## datetime in pandas\n",
    "1. index=datetime => DatetimeIndex对象，数据结构是Numpy Datetime64，精度ns\n",
    "2. DatetimeIndex中的每一个元素是pandas.timestamp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "068744b7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
